/**
 *
 */
package com.nest.WorkNest.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nest.WorkNest.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 */
public class LargeOrderAdapter extends BaseAdapter {

    private ArrayList<HashMap<String, String>> dataList;
    private Context context;

    public LargeOrderAdapter(Context context, ArrayList<HashMap<String, String>> dataList) {

        this.dataList = dataList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.items_listview_largeorderment, null);
            holder.color = (TextView) convertView.findViewById(R.id.act_color);
            holder.size = (TextView) convertView.findViewById(R.id.act_size);
            holder.count = (TextView) convertView.findViewById(R.id.act_count);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        HashMap<String, String> map = dataList.get(position);
        holder.color.setText(map.get("color"));
        holder.size.setText(map.get("size"));
        holder.count.setText(map.get("quantity"));

        return convertView;
    }

    private class ViewHolder {
        TextView color, size, count;
    }

    public void update(ArrayList<HashMap<String, String>> dataList) {
        for (int i = 0; i < dataList.size(); i++) {
            if ("0".equals(dataList.get(i).get("quantity"))) {
                dataList.remove(i);
                i=0;
            }
        }
        this.dataList = dataList;
        notifyDataSetChanged();
    }
}
